import java.util.HashMap;
import java.util.Map;

public class Solution1 {
    public static int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hash = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            hash.put(nums[i],i);
        }
        int[] ret = new int[2];
        for (int i = 0; i < nums.length; i++) {
            int x = target - nums[i];
            int index = hash.getOrDefault(x,-1);
            if (index != -1) {
                ret[0] = i;
                ret[1] = index;
                return ret;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] nums = {3,2,4};
        int[] ret = new int[2];
        ret = twoSum(nums,6);
    }
}
